//Cracking coding interview, 17.7
//Print integer description
//10:44AM--11:04AM--11:16AM(bug free)
#include<sstream>
#include<iostream>
using namespace std;

char* LUT[]={"Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"};
char* LUT1[]={"Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Nineteen"};

void IntDescrip(int i, stringstream &ss) {
	if (i<0) {
		ss<<"Minus ";
		i*=-1;
	}
	if (i==0) {
		ss<<"Zero";
	} else {
		int j=i/1000000000;
		if (j>=1) {
			IntDescrip(j, ss);
			i-=j*1000000000;
			ss<<"Billion, ";
		}
		j=i/1000000;
		if(j>=1) {
			IntDescrip(j, ss);
			i-=j*1000000;
			ss<<"Million, ";
		}
		j=i/1000;
		if(j>=1) {
			IntDescrip(j, ss);
			i-=j*1000;
			ss<<"Thousand, ";
		}
		j=i/100;
		if(j>=1) {
			i-=j*100;
			ss<<LUT[j]<<" Hundred ";
		}
		j=i/10;
		if(j>=1) {
			i-=j*10;
			switch (j) {
			case 0:
				if(i)
					ss<<LUT[i]<<" ";
				break;
			case 1:
				ss<<LUT1[i]<<" ";
				break;
			case 2:
				ss<<"Twenty ";
				break;
			case 3:
				ss<<"Thirty ";
				break;
			default:
				ss<<LUT[j]<<"ty"<<" ";
				break;
			}
		}
		
		if(i) {
			ss<<LUT[i]<<" ";
		}
	}
}

int main(int argc, char *argv[]) {
	stringstream ss;
	IntDescrip(1234999, ss);
	cout<<ss.str();
	return 0;
}